<!-- 申请弹窗 -->
<template>

  <el-container>
    <el-main class="application-main">
      <div v-for="v in result" :key="v.id" class="application-row">
        <el-row class="info-top">
          <!-- <el-col :span="12">
            <h5>{{ data.itemCode }}</h5>
          </el-col> -->
          <el-col v-if="v.reviewUserToName" :span="12" :offset="12" class="t-r">
            <span>审核人：{{ v.reviewUserToName }}</span>
          </el-col>
        </el-row>
        <el-row class="info-body">
          <el-col :span="6">
            <span>申请人:<small>{{ v.createUserToName }}</small></span>
          </el-col>
          <el-col :span="12">
            <span>申请时间: <small> {{ v.createTime }}</small></span>
          </el-col>
          <el-col :span="6">
            <span>申请状态：
              <small :style="v.state | state('color')">
                {{ v.state | state }}
              </small>
            </span>
          </el-col>
        </el-row>
        <el-row class="info-bottom">
          <el-col :span="24">
            <h5>{{ v.remark }}</h5>
          </el-col>
        </el-row>
        <el-row v-if="v.state === 1" class="button-group">
          <el-col :offset="16" :span="4" class="t-r">
            <el-button
              type="danger"
              size="mini"
              class="btn"
              @click="option(v.id, 'reject')"
            >
              驳回
            </el-button>
          </el-col>
          <el-col :span="4" class="t-r">
            <el-button
              type="primary"
              class="btn"
              size="mini"
              @click="option(v.id, 'pass')"
            >
              通过
            </el-button>
          </el-col>
        </el-row>
      </div>
    </el-main>
  </el-container>
  <!-- <template v-else>
    <h4 style="text-align: center">暂无数据!!</h4>
  </template> -->
</template>

<script>
import ProjectAPI from '@/apis/project';
export default {
  filters: {
    state(code, field = 'text') {
      const status = {
        1: {
          color: '#409EFF',
          text: '待审核',
        },
        2: {
          color: '#67C23A',
          text: '通过',
        },
        3: {
          color: '#F56C6C',
          text: '驳回',
        },
      };
      const val = field === 'text' ? status[code][field] : 'color:' + status[code][field];
      return val;
    },
  },
  props: {
    data: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      result: [],
    };
  },

  created() {
    this.open();
  },
  methods: {
    async open() {
      const value = await ProjectAPI.impose.changeList(
        this.data.itemCode
      );
      this.result = value;
    },
    async option(v, t) {
      try {
        await ProjectAPI.impose.changeApply(v, t);
        this.$message.success('操作成功');
        this.$emit('done');
      } catch (e) {
        this.$message.error(e);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.t-r {
  text-align: right;
}
.application {
  &-main{
    height:auto;
    max-height: 600px;
    overflow: auto;
  }
  &-row{

    margin-bottom: 56px;
  }
  h5 {
    padding: 0;
    margin: 0;
  }

  .button{
    &-group{
      margin-top: 32px;
    }
  }
}
  .info {
    &-top {
      margin-bottom: 16px;
      h5 {
        font-size: 18px;
        font-weight: 400;
        color: #2d405e;
      }
    }
    &-body {
      span {
        font-size: 18px;
        font-weight: 400;
        color: #879bba;
      }
      small {
        font-size: 18px;
        font-weight: 400;
        color: #2d405e;
      }
    }
    &-bottom {
      margin-top: 16px;
      h5 {
        font-size: 18px;
        font-weight: 400;
        color: #2d405e;
      }
    }
  }
</style>
